package com.study.system.common.result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
//用于统一接口调用的返回格式，包括成功和失败的情况处理，以及判断操作结果是否成功的方法，

@Data
public class TableResult<T> implements Serializable {

    private String code;

    private Data<T> data;

    private String msg;

    public static <T> TableResult<T> success(List<T> list) {
        TableResult<T> result = new TableResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());

        Data data = new Data<T>();
        data.setList(list);
        data.setTotal(list.size());

        result.setData(data);
        result.setMsg(ResultCode.SUCCESS.getMsg());
        return result;
    }

    @lombok.Data
    public static class Data<T> {

        private List<T> list;

        private long total;

    }

}
